SlideExpandableListView滑动显示隐藏面板 您所在的位置:网站首页 axure 折线图 SlideExpandableListView滑动显示隐藏面板

SlideExpandableListView滑动显示隐藏面板

2023-04-10 18:57| 来源: 网络整理| 查看: 265

SlideExpandableListView滑动显示隐藏面板 原创

gundumw100 2023-04-07 10:19:46 ©著作权

文章标签 android ide xml 文章分类 JavaScript 前端开发

©著作权归作者所有:来自51CTO博客作者gundumw100的原创作品,请联系作者获取转载授权,否则将追究法律责任

快速实现一个滑动显示隐藏面板的ListView

SlideExpandableListView滑动显示隐藏面板_android

基本用法:

listView = (ListView) view.findViewById(R.id.listView); protected void notifyDataSetChanged() { if (adapter == null) { adapter = new CommonAdapter(context, beans, layoutId) { @Override public void setValues(ViewHolder helper, T item, int position) { createItem(helper, item, position); } }; listView.setAdapter(new SlideExpandableListAdapter(adapter, R.id.expandable_toggle_button, R.id.expandable)); } else { adapter.notifyDataSetChanged(); } }

在你的item布局文件中需要有ID为expandable_toggle_button的把手,和ID为expandable的面板容器

典型的像下面这样:

如果你嫌上面的做法麻烦:

还有简单的,使用ActionSlideExpandableListView控件,无需指定具体的把手ID和面板ID;

但是我通常不这样做,因为毕竟使用的是ActionSlideExpandableListView,而不是普通的ListView,扩展性可能会受限制。

附件使用的是ActionSlideExpandableListView控件

public class MainActivity extends Activity { @Override public void onCreate(Bundle savedData) { super.onCreate(savedData); // set the content view for this activity, check the content view xml file // to see how it refers to the ActionSlideExpandableListView view. this.setContentView(R.layout.single_expandable_list); // get a reference to the listview, needed in order // to call setItemActionListener on it ActionSlideExpandableListView list = (ActionSlideExpandableListView)this.findViewById(R.id.list); // fill the list with data list.setAdapter(buildDummyData()); // listen for events in the two buttons for every list item. // the 'position' var will tell which list item is clicked list.setItemActionListener(new ActionSlideExpandableListView.OnActionClickListener() { @Override public void onClick(View listView, View buttonview, int position) { /** * Normally you would put a switch * statement here, and depending on * view.getId() you would perform a * different action. */ String actionName = ""; if(buttonview.getId()==R.id.buttonA) { actionName = "buttonA"; } else { actionName = "ButtonB"; } /** * For testing sake we just show a toast */ Toast.makeText( MainActivity.this, "Clicked Action: "+actionName+" in list item "+position, Toast.LENGTH_SHORT ).show(); } // note that we also add 1 or more ids to the setItemActionListener // this is needed in order for the listview to discover the buttons }, R.id.buttonA, R.id.buttonB); } /** * Builds dummy data for the test. * In a real app this would be an adapter * for your data. For example a CursorAdapter */ public ListAdapter buildDummyData() { final int SIZE = 40; String[] values = new String[SIZE]; for(int i=0;i 收藏 评论 分享 举报

上一篇:MultiStateView不同的状态下显示不同的界面

下一篇:android5.x之Palette调色板



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有